<template>
  <div class="login-page">
    <div class="login-title">
      <h1>面经登录</h1>
    </div>
    <div class="login-form">
      <div class="login-username">
        <label for="username" style="width: 15%">用户名</label>
        <input type="text" placeholder="用户名" v-model="username" />
      </div>
      <div class="login-password">
        <label for="password" style="width: 15%">密码</label>
        <input
          type="password"
          placeholder="密码"
          v-model="password"
          @keyup.enter="Login"
        />
      </div>
      <div class="login-submit">
        <button class="login-submit-button" @click="Login">提交</button>
      </div>
      <div class="login-register">
        <router-link to="/register" class="login-register-button">
          注册账号
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "vant";
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    Login() {
      axios({
        url: "http://interview-api-t.itheima.net/h5/user/login",
        method: "post",
        data: {
          username: this.username,
          password: this.password,
        },
      })
        .then((res) => {
          // console.log(res);
          if (res.data.code === 10000) {
            this.$router.push(`/main/interview/recommend`);
            localStorage.setItem("token", res.data.data.token);
          }
        })
        .catch(() => {
          Toast("用户信息不存在");
        });
    },
  },
};
</script>

<style lang="less" scoped>
.login-page {
  width: 90%;
  height: 100%;
  margin: 0 auto;
  //   background-color: #f0f0f0;
  //   padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  // padding: 0 10px;
  .login-title {
    h1 {
      text-align: center;
      font-size: 20px;
      font-weight: 500;
    }
  }
  .login-form {
    width: 100%;
    height: 100%;
    .login-username {
      display: flex;
      height: 40px;
      margin-bottom: 10px;
      align-items: center;
      justify-content: space-evenly;
      border-bottom: 1px solid #ccc;
    }
    .login-password {
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      height: 40px;
      border-bottom: 1px solid #ccc;
      margin-bottom: 10px;
    }
  }
  .login-submit-button {
    //居中
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
    margin-bottom: 15px;
    width: 100%;
    height: 40px;
    background-color: #fa6d1d;
    color: #fff;
    font-size: 16px;
    font-weight: 500;
    border: none;
    outline: none;
  }
}
input {
  width: 75%;
  height: 30px;
  border: none;
  border-radius: 5px;
  outline: none;
}
.login-register {
  display: flex;
  justify-content: end;
  align-items: center;
  margin-top: 10px;
  .login-register-button {
    color: #3284a4;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
  }
}
</style>
